package com.hzy.fivepalace.admin.controller;

import com.hzy.fivepalace.admin.annotation.Login;
import com.hzy.fivepalace.admin.controller.base.BaseController;
import com.hzy.fivepalace.admin.service.CommonService;
import com.hzy.fivepalace.common.util.TableDataInfo;
import com.hzy.fivepalace.db.domain.DtsSinceSite;
import com.hzy.fivepalace.db.domain.DtsVideo;
import com.hzy.fivepalace.db.domain.DtsVipConfig;
import com.hzy.fivepalace.db.service.DtsSinceSiteService;
import com.hzy.fivepalace.db.vo.ReturnAdressVo;
import com.hzy.fivepalace.db.vo.admin.AdminAddHomeModuleChildVo;
import com.hzy.fivepalace.db.vo.admin.AdminHomeModuleParentVo;
import com.hzy.fivepalace.db.vo.admin.AdminUpdHomeModuleChildVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;


/**
 * 平台管理
 *
 * @author gejian
 */
@RestController
@RequestMapping("/admin/platform/manage")
@Api(tags = "平台管理")
@ResponseBody
@Login
public class AdminPlatformManageController extends BaseController {

    @Resource
    private CommonService commonService;

    @Resource
    private DtsSinceSiteService sinceSiteService;

    /**
     * 修改会员配置
     *
     * @param vipConfig
     * @return
     */
    @PostMapping("/updateVipConfig")
    @ApiOperation(value = "修改会员配置")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public Object updateVipConfig(DtsVipConfig vipConfig, @ApiParam(value = "商品json字符串") @RequestParam(value = "goodsInfo", required = false) String goodsInfo) {

        return commonService.updateVipConfig(vipConfig, goodsInfo);
    }

    /**
     * 获取vip配置详情
     *
     * @param vipId
     * @return
     */
    @PostMapping("/getVipConfigDetail")
    @ApiOperation(value = "获取vip配置详情")
    public Object getVipConfigDetail(@ApiParam(value = "会员ID") @NotNull Long vipId) {
        return commonService.getVipConfigDetail(vipId);
    }


    /**
     * 获取会员配置列表
     *
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/getVipConfigList")
    @ApiOperation(value = "获取会员配置列表")
    public TableDataInfo getVipConfigList(@ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page, @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "100") Integer size) {
        return commonService.getVipConfigList(page, size);
    }

    /**
     * 获取自提点信息
     *
     * @return
     */
    @PostMapping("/getSinceSiteInfo")
    @ApiOperation(value = "获取自提点信息")
    public Object getSinceSiteInfo() {
        return sinceSiteService.getSinceSiteInfo();
    }

    /**
     * 修改自提点信息
     *
     * @param sinceSite
     * @return
     */
    @PostMapping("/updSinceSite")
    @ApiOperation(value = "修改自提点信息")
    public Object updSinceSite(DtsSinceSite sinceSite) {
        return sinceSiteService.updSinceSite(sinceSite, getAdminId());
    }

    /**
     * 静态页面列表
     *
     * @param type
     * @return
     */
    @PostMapping("/getHtmlList")
    @ApiOperation(value = "静态页面列表")
    public Object getHtmlList(@ApiParam(value = "检索用:静态页面类型") @RequestParam(value = "type", defaultValue = "", required = false) Integer type) {

        return commonService.getHtmlList(type);
    }

    /**
     * 静态页面详情
     *
     * @param id
     * @return
     */
    @PostMapping("/getHtmlDetails")
    @ApiOperation(value = "静态页面详情")
    public Object getHtmlDetails(@ApiParam(value = "数据id") @RequestParam(value = "id") @NotNull Integer id) {
        return commonService.getHtmlDetails(id);
    }

    /**
     * 赠送会员
     *
     * @param userId
     * @param vipType
     * @param msg
     * @return
     */
    @PostMapping("/giveVip")
    @ApiOperation(value = "赠送会员")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public Object giveVip(@ApiParam(value = "数据id") @RequestParam(value = "userId") @NotNull Integer userId, @ApiParam(value = "会员类型:1PLUS会员,2代理商,3合伙人,4联合创始人") @RequestParam(value = "vipType") @NotNull Integer vipType, @ApiParam(value = "赠送原因,可不填") @RequestParam(value = "msg", defaultValue = "", required = false) String msg

    ) {

        return commonService.giveVip(userId, vipType, msg);
    }

    /**
     * 修改静态页面
     *
     * @param id
     * @param content
     * @return
     */
    @PostMapping("/updHtml")
    @ApiOperation(value = "修改静态页面")
    public Object updHtml(@ApiParam(value = "数据id") @RequestParam(value = "id") @NotNull Integer id, @ApiParam(value = "内容") @RequestParam(value = "content") @NotBlank String content) {

        return commonService.updHtml(id, content);
    }

    /**
     * 首页轮播图
     *
     * @return
     */
    @PostMapping("/getBanner")
    @ApiOperation(value = "首页轮播图")
    public Object getBanner() {

        return commonService.getHomeSlideshow();
    }

    /**
     * 删除轮播图
     *
     * @return
     */
    @PostMapping("/delBanner")
    @ApiOperation(value = "删除轮播图")
    public Object delBanner(@ApiParam(value = "数据id") @RequestParam(value = "id") @NotNull Integer id) {

        return commonService.delBanner(id);
    }


    /**
     * 新增首页轮播图
     *
     * @param imgUrl
     * @param jumpUrl
     * @param sort
     * @return
     */
    @PostMapping("/addBanner")
    @ApiOperation(value = "新增首页轮播图")
    public Object addBanner(@ApiParam(value = "图片地址,必填", required = true) @RequestParam(value = "imgUrl") @NotBlank String imgUrl, @ApiParam(value = "跳转链接,非必填") @RequestParam(value = "jumpUrl", required = false) String jumpUrl, @ApiParam(value = "排序") @RequestParam(value = "sort", required = false) Integer sort

    ) {

        return commonService.addBanner(imgUrl, jumpUrl, sort);
    }

    @PostMapping("/updBanner")
    @ApiOperation(value = "修改首页轮播图")
    public Object updBanner(@ApiParam(value = "数据id") @RequestParam(value = "id") @NotNull Integer id, @ApiParam(value = "图片地址,必填", required = true) @RequestParam(value = "imgUrl") @NotBlank String imgUrl, @ApiParam(value = "跳转链接") @RequestParam(value = "jumpUrl", required = false) String jumpUrl, @ApiParam(value = "排序") @RequestParam(value = "sort", required = false) Integer sort) {

        return commonService.updBanner(imgUrl, jumpUrl, sort, id);
    }


    /**
     * 运费配置详情
     *
     * @return
     */
    @PostMapping("/getFreightConfigDetails")
    @ApiOperation(value = "运费配置详情")
    public Object getFreightConfigDetails() {

        return commonService.getFreightConfigDetails();
    }


    /**
     * 新类目下拉选
     *
     * @return
     */
    @PostMapping("/getNewCategorySelect")
    @ApiOperation(value = "新类目下拉选")
    public Object getNewCategoryList() {
        return commonService.getNewCategorySelect();
    }

    /**
     * 修改运费配置
     *
     * @return
     */
    @PostMapping("/updFreightConfig")
    @ApiOperation(value = "修改运费配置")
    public Object updFreightConfig(@ApiParam(value = "免费包邮金额") @RequestParam(value = "freeFreightMoney", required = false) BigDecimal freeFreightMoney, @ApiParam(value = "不满足免费包邮时运费") @RequestParam(value = "freight", required = false) BigDecimal freight) {

        return commonService.updFreightConfig(freeFreightMoney, freight);
    }


    /**
     * 意见反馈列表
     *
     * @param content
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/feedbackList")
    @ApiOperation(value = "意见反馈列表")
    public TableDataInfo feedbackList(@ApiParam(value = "内容") @RequestParam(value = "content", required = false) String content, @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page, @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "100") Integer size) {

        return commonService.feedbackList(content, page, size);
    }


    /**
     * 首页模块列表-父级
     *
     * @return
     */
    @PostMapping("/getHomeModuleParentList")
    @ApiOperation(value = "首页模块列表-父级")
    public TableDataInfo getHomeModuleParentList(@ApiParam(value = "内容") @RequestParam(value = "content", required = false) String content, @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page, @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "100") Integer size) {

        return commonService.getHomeModuleParentList(content, page, size);
    }

    /**
     * 新增或修改首页模块-父级
     *
     * @param vo
     * @return
     */
    @PostMapping("/addOrUpdHomeModuleParent")
    @ApiOperation(value = "新增或修改首页模块-父级")
    public Object addOrUpdHomeModuleParent(AdminHomeModuleParentVo vo) {

        return commonService.addOrUpdHomeModuleParent(vo);
    }

    /**
     * 删除首页模块-父级
     *
     * @param indexId
     * @return
     */
    @PostMapping("/delHomeModuleParent")
    @ApiOperation(value = "删除首页模块-父级")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public Object delHomeModuleParent(@ApiParam(value = "模块id") @RequestParam(value = "indexId") @NotNull Integer indexId) {

        return commonService.delHomeModuleParent(indexId);
    }

    /**
     * 首页模块列表-不分页
     *
     * @param indexId
     * @param content
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/getHomeModuleChildList")
    @ApiOperation(value = "首页模块列表-子级-不分页")
    public Object getHomeModuleChildList(@ApiParam(value = "父级id") @RequestParam(value = "indexId") @NotNull Integer indexId, @ApiParam(value = "内容") @RequestParam(value = "content", required = false) String content, @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page, @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "100") Integer size) {

        return commonService.getHomeModuleChildList(content, page, size, indexId);
    }

    /**
     * 删除首页模块-子级(包含下面所有商品)
     *
     * @param childId
     * @return
     */
    @PostMapping("/delHomeModuleChild")
    @ApiOperation(value = "删除首页模块-子级(包含下面所有商品)")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public Object delHomeModuleChild(@ApiParam(value = "childId") @RequestParam(value = "childId") @NotNull Integer childId) {

        return commonService.delHomeModuleChild(childId);
    }

    /**
     * 新增首页模块-子级
     *
     * @param vo
     * @return
     */
    @PostMapping("/addHomeModuleChild")
    @ApiOperation(value = "新增首页模块-子级")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public Object addHomeModuleChild(AdminAddHomeModuleChildVo vo) {

        return commonService.addHomeModuleChild(vo);
    }

    /**
     * 修改首页模块-子级
     *
     * @param vo
     * @return
     */
    @PostMapping("/updHomeModuleChild")
    @ApiOperation(value = "修改首页模块-子级")
    public Object updHomeModuleChild(AdminUpdHomeModuleChildVo vo) {

        return commonService.updHomeModuleChild(vo);
    }

    /**
     * 新增模块商品
     *
     * @param childId
     * @param goodsIds
     * @return
     */
    @PostMapping("/addHomeModuleGoods")
    @ApiOperation(value = "新增模块商品")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public Object addHomeModuleGoods(@ApiParam(value = "子级id") @RequestParam(value = "childId") @NotNull Integer childId, @ApiParam(value = "商品id,多个用英文逗号隔开") @RequestParam(value = "goodsIds") @NotBlank String goodsIds) {

        return commonService.addHomeModuleGoods(childId, goodsIds);
    }


    @PostMapping("/delHomeModuleGoods")
    @ApiOperation(value = "删除模块商品")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public Object delHomeModuleGoods(@ApiParam(value = "子级id") @RequestParam(value = "childId") @NotNull Integer childId, @ApiParam(value = "商品id,多个用英文逗号隔开") @RequestParam(value = "goodsIds") @NotBlank String goodsIds) {

        return commonService.delHomeModuleGoods(childId, goodsIds);
    }

    /**
     * 品牌视频列表
     *
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/getVideoList")
    @ApiOperation(value = "品牌视频列表")
    public Object getVideoList(@ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page, @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer size, @ApiParam(value = "标题") @RequestParam(value = "title", required = false) String title, @ApiParam(value = "是否为推荐") @RequestParam(value = "recommend", required = false) Boolean recommend) {

        return commonService.getVideoList(page, size, title, recommend);
    }

    /**
     * 新增视频
     *
     * @param video
     * @return
     */
    @PostMapping("/addVideo")
    @ApiOperation(value = "新增视频")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public Object addVideo(DtsVideo video) {

        return commonService.addVideo(video);
    }

    /**
     * 修改视频
     *
     * @param video
     * @return
     */
    @PostMapping("/updVideo")
    @ApiOperation(value = "修改视频")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public Object updVideo(DtsVideo video) {

        return commonService.updVideo(video);
    }


    /**
     * 设置为推荐视频
     *
     * @param id
     * @return
     */
    @PostMapping("/setVideoRecommend")
    @ApiOperation(value = "设置为推荐视频")
    public Object setVideoRecommend(@ApiParam(value = "视频id") @RequestParam(value = "id") @NotNull Integer id) {

        return commonService.setVideoRecommend(id);
    }

    /**
     * 取消推荐视频
     *
     * @param id
     * @return
     */
    @PostMapping("/cancelVideoRecommend")
    @ApiOperation(value = "取消推荐视频")
    public Object cancelVideoRecommend(@ApiParam(value = "视频id") @RequestParam(value = "id") @NotNull Integer id) {

        return commonService.cancelVideoRecommend(id);
    }

    @PostMapping("/delVideo")
    @ApiOperation(value = "删除视频")
    public Object delVideo(@ApiParam(value = "视频id") @RequestParam(value = "id") @NotNull Integer id) {

        return commonService.delVideo(id);
    }

    /**
     * 获取推荐视频
     *
     * @return
     */
    @PostMapping("/getRecommendVideo")
    @ApiOperation(value = "获取推荐视频")
    public Object getRecommendVideo() {

        return commonService.getRecommendVideo();
    }

    /**
     * 获取退货地址详情
     *
     * @return
     */
    @PostMapping("/getReturnAdress")
    @ApiOperation(value = "获取退货地址详情")
    public Object getReturnAdress() {

        return commonService.getReturnAdress();
    }

    @PostMapping("/updReturnAdress")
    @ApiOperation(value = "修改退货地址")
    public Object updReturnAdress(ReturnAdressVo vo) {

        return commonService.updReturnAdress(vo);
    }

}
